# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: dtag <dtag00@gmail.com>
pkgname=ceres-solver
pkgver=2.1.0
pkgrel=3
pkgdesc="Solver for nonlinear least squares problems"
arch=('loong64' 'x86_64')
url="http://ceres-solver.org/"
license=('LGPL')
depends=('google-glog' 'eigen' 'suitesparse')
makedepends=('cmake' 'ninja')
optdepends=('openmp')
source=("http://ceres-solver.org/ceres-solver-2.1.0.tar.gz"
        "0001-fix-for-suitesparse-6.0.0.patch")
sha256sums=('f7d74eecde0aed75bfc51ec48c91d01fe16a6bf16bce1987a7073286701e2fc6'
            '0eb45170ec3e87839a688b78ce2d2cffe562a7aa3d10619043729252d3a56d79')
options=('staticlibs')

prepare() {
  cd $pkgname-$pkgver
  patch -p1 -i "$srcdir"/0001-fix-for-suitesparse-6.0.0.patch
}

build() {
  cd $pkgname-$pkgver
  cmake \
      -Bbuild \
      -GNinja \
      -DCMAKE_BUILD_TYPE=None \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DEIGENSPARSE=ON \
      -DBUILD_SHARED_LIBS=ON \
      -DBUILD_TESTING=OFF \
      -DBUILD_EXAMPLES=OFF \
      -DBUILD_BENCHMARKS=OFF

  ninja -C build
}

package() {
  cd $pkgname-$pkgver
  DESTDIR=$pkgdir ninja -C build install
  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
